import React, { Component } from 'react';
import { Modal, Button, Form, Input } from 'antd';
import 'antd/dist/antd.css';
// 组件名自己起，这里是D
class TWiceModal extends Component {
  constructor(props) {
    debugger
    super(props);
    this.state = {
      visible: this.props.visible, //由父组件的props决定，this.props.xx
      name: this.props.data
    }
  }
  // 生命周期函数，接受传入的props，现在这个生命周期仍可以用。官网推荐使用新的生命周期static
  // getDerivedStateFromProps，它的state永远取决于父组件的props，将在后续文章探索它的使用方法。
  componentWillReceiveProps(nextProps) {
    this.setState({
      visible: nextProps.visible
    })
  }

  handleOk = e => {
    this.setState({
      visible: false,
    }, () => console.log(' handleOk visible', this.state.visible));
    this.props.AA(); //在子组件中调用父组件的AA方法
  };

  // handleCancel = e => {
  //   this.setState({
  //     visible: false
  //   }, () => {
  //     this.props.visible=false
  //   });
  // };

  handleCancel = e => {
    debugger;
    this.props.setState={
      visible:false
    }
  };



  render() {
    console.log('render visible', this.state.visible)
    return (
      <div>
        <Modal
          visible={this.state.visible}
          title={<span>修改报告单</span>}

          okText="确认"
          cancelText="取消"
          onOk={this.handleOk}
          onCancel={this.handleCancel}
        >
          <Form layout='inline'>
            <Form.Item label='初检人' name={'checkperson'}>
              <Input defaultValue={this.state.name} />
            </Form.Item>
          </Form>
        </Modal>
      </div>

    );
  }
}

export default TWiceModal;
